package com.loveprogrammer.model;

import com.loveprogrammer.engine.AttackResult;
import com.loveprogrammer.engine.enums.MonsterQualityEnum;
import com.loveprogrammer.factory.template.JobTemplate;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @version 1.0.0
 * @description:
 * @author: eric
 * @date: 2022-08-02 16:41
 **/
public class Hero extends Character{

    private JobTemplate template;

    public Hero(String name, int strength, int armature, int constitution, int magic, int technique, int speed,
                AtomicInteger hp, int hpMax, int baseStrength, int baseArmature, int baseConstitution, int baseMagic,
                int baseTechnique, int baseSpeed, int baseHp, int level, MonsterQualityEnum monsterQualityEnum,
                Integer currentExp, Integer nextLevelNeedExp, int attackType, JobTemplate template, int poisonResistance,
                int flameResistance, int thunderResistance,int iceResistance,int position) {
        super(template.getId(),name,strength,armature,constitution,magic,technique,speed,hp,hpMax,baseStrength,baseArmature,
                baseConstitution,baseMagic,baseTechnique,baseSpeed,baseHp,level,monsterQualityEnum,currentExp,
                nextLevelNeedExp,attackType,poisonResistance,flameResistance,thunderResistance,iceResistance,position);
        this.template = template;
    }


    public Hero(String name, JobTemplate template) {
        super(template.getId(),name,0,template.getStrength(),template.getArmature(),template.getConstitution(),
                template.getMagic(),template.getTechnique(),template.getSpeed(),template.getAttackType(),template.getPoisonResistance(),
                template.getFlameResistance(), template.getThunderResistance(),template.getIceResistance(),template.getPosition());
        this.template = template;
    }

    @Override
    public void levelUp(int exp) {
        this.setLevel(this.level + 1);
        // 属性增加
        this.setStrength(this.strength + template.getLevelUpStrength());
        this.setTechnique(this.technique + template.getLevelUpTechnique());
        this.setArmature(this.armature + template.getLevelUpArmature());
        this.setConstitution(this.constitution + template.getLevelUpConstitution());
        this.hp.addAndGet(10 * template.getLevelUpConstitution());
        this.hpMax = this.hp.get();
        this.setMagic(this.magic + template.getLevelUpMagic());
        // this.setTechnique(this.technique + template.getLevelUpTechnique());
        this.setSpeed(this.speed + template.getLevelUpSpeed());
        // 基础属性增加
        this.setBaseStrength(this.getBaseStrength() + template.getLevelUpStrength());
        this.setBaseTechnique(this.getBaseTechnique() + template.getLevelUpTechnique());
        this.setBaseArmature(this.getBaseArmature() + template.getLevelUpArmature());
        this.setBaseConstitution(this.getBaseConstitution() + template.getLevelUpConstitution());
        this.setBaseMagic(this.getBaseMagic() + template.getLevelUpMagic());
        // this.setBaseTechnique(this.technique);
        this.setBaseSpeed(this.getBaseSpeed() + template.getLevelUpSpeed());

        // 计算下一级需要的经验值
        int needExp = this.setNextLevelNeedExp();
        if(exp > needExp){
            levelUp(exp);
        }
    }

    @Override
    public AttackResult attack(List<? extends Character> defence) {

        return simpleAttack(defence);
    }

    @Override
    public int getDeadExp() {
        return 0;
    }

    public JobTemplate getTemplate() {
        return template;
    }
}
